//
//  OtherBillViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/11/5.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class OtherBillViewController: BillRootViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = otherBill
        addSubView()
        
    }
    
    //MARK: 添加子视图
    fileprivate func addSubView() {
        
        let scrollView = UIScrollView()
        scrollView.backgroundColor = UIColor.mineColor()
        scrollView.showsVerticalScrollIndicator = false
        scrollView.bounces = false
        self.view.addSubview(scrollView)
        
        let commonBillView = CommonBillView()
        scrollView.addSubview(commonBillView)
        
        let lifeBillView = LifeBillView()
        lifeBillView.delegate = self
        scrollView.addSubview(lifeBillView)
        
        let customBillView = CustomBillView()
        customBillView.customBtn.addTarget(self, action: #selector(addCustomBill), for: .touchUpInside)
        scrollView.addSubview(customBillView)
        
        commonBillView.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.left.right.equalTo(self.view)
            make.height.equalTo(RATIO_H(maxNum: 230))
        }
        
        scrollView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.zero)
        }
        
        lifeBillView.snp.makeConstraints { (make) in
            make.top.equalTo(commonBillView.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.left.right.equalTo(self.view)
            make.height.equalTo(RATIO_H(maxNum: 370))
        }
        
        customBillView.snp.makeConstraints { (make) in
            make.top.equalTo(lifeBillView.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.left.right.equalTo(self.view)
            make.height.equalTo(RATIO_H(maxNum: 50))
        }
        
        self.view.layoutIfNeeded()
        
        scrollView.contentSize = .init(width: ScreenW, height: customBillView.frame.maxY + RATIO_H(maxNum: 50))
    }
    
    //MARK: 添加自定义账单
    @objc fileprivate func addCustomBill() {
        
        self.navigationController?.pushViewController(CustomBillViewController(), animated: true)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
}

extension OtherBillViewController : LifeBillViewDelegate {
    
    //MARK: 选择账单类型
    func selectBillType(title: String) {
        
        let lifeBillVC = LifeViewController.init(title: title)
        self.navigationController?.pushViewController(lifeBillVC, animated: true)
    }
}
